﻿/**加载表格函数
Begin
obj_ID:元素ID, url:请求地址, colM:表头名称, sort:要显示字段, PageSize：每页大小
来源：http://www.cnblogs.com/
**/
var GetRowIndex = -1; //索引号
var _curObj = null;
var container = window;
function LoadGrid(obj_ID, url, colM, sort, PageSize, topVisible) {
    GetRowIndex = -1;
    var dataModel = {
        location: "remote",
        sorting: "remote",
        paging: "remote",
        dataType: "JSON",
        method: "GET",
        curPage: 1,
        rPP: PageSize,
        sortIndx: 0,
        sortDir: "up",
        rPPOptions: [20, 30, 40, 50, 100, 500, 1000],
        getUrl: function () {
            return { url: url };
        },
        getData: function (dataJSON) {
            if (dataJSON == null && dataJSON.totalRecords <= 0) {
                showTipsMsg("没有找到您要的相关数据！", 5000, 5);
            }
            return { curPage: dataJSON.curPage, totalRecords: dataJSON.total, data: dataJSON.rows };
        }
    }
    if (!IsNullOrEmpty(topVisible)) {
        topVisible = false;
    }
    $(obj_ID).pqGrid({
        dataModel: dataModel,
        colModel: colM,
        editable: false,
        topVisible: topVisible,
        //oddRowsHighlight: false,
        columnBorders: true,
        freezeCols: 1,
        getUrl: function () {
            var orderField = (this.sortIndx == "0") ? "" : sort[this.sortIndx];
            var sortDir = (this.sortDir == "up") ? "desc" : "asc";
            return {
                url: url, data: ""
            };
        },
        rowSelect: function (evt, ui) {
            GetRowIndex = ui.rowIndxPage;
        }
    });
    pqGridResize(obj_ID, -41, -4);
}

/**表格自应高度
obj：ID，lose_height:-高度,lose_width:-宽度
**/
function pqGridResize(obj, lose_height, lose_width) {
    var grid_height = $(window).height() + lose_height;
    var grid_width = $(container).width() + lose_width;
    var grid1 = $(obj).pqGrid({
        width: grid_width,
        height: grid_height
    });
}
/**表格自应高度
obj：ID，lose_height:-高度,lose_width:-宽度
**/
function pqGridResizefixed(obj, lose_height, lose_width) {
    var grid_width = $(container).width() + lose_width;
    var grid1 = $(obj).pqGrid({
        width: grid_width,
        height: lose_height
    });
}
/**获取表格列值
obj：ID，rowCode：列号
**/
function GetPqGridRowValue(obj_ID, rowCode) {
    if (GetRowIndex != -1) {
        var DM = $(obj_ID).pqGrid("option", "dataModel");
        var data = DM.data;
        return data[GetRowIndex][rowCode];
    }
    else {
        return null;  
    }
}


//验证是否为空
function IsNullOrEmpty(str) {
    var isOK = true;
    if (str == undefined || str == "") {
        isOK = false;
    }
    return isOK;
}


//
function fnCheckInput(e) {
     return "<input type=checkbox id='"+e.ID+"'/>";
}